package main.java.indi.zyj.c150.dp;

public class _23_MaxSubArray {

    public int maxSubArray(int[] nums) {

        int len = nums.length;

        if (len == 0)
            return 0;

        int[] dp = new int[len];
        dp[0] = nums[0];

        for (int i = 1; i < len; i++) {
            dp[i] = Math.max(nums[i], nums[i] + dp[i-1]);
        }

        // 得到 nums 的最大子数组
        int res = Integer.MIN_VALUE;
        for (int i = 0; i < len; i++) {
            res = Math.max(res, dp[i]);
        }
        return res;


    }



}
